import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAwardStore = defineStore('awardStore', () => {
    const awards = ref([
        {
            awardId: 1,
            awardName: '一个奖',
            description: '这个奖特别好',
            dateAwarded: '2022-12-01'
        }
    ])

    const setAwards = (newAwards) => {
        awards.value = newAwards
    }

    const addAward = (award) => {
        awards.value.push(award)
    }

    const updateAward = (updatedAward) => {
        const index = awards.value.findIndex(award => award.awardId === updatedAward.awardId)
        if (index !== -1) {
            awards.value[index] = updatedAward
        }
    }

    const deleteAward = (awardId) => {
        awards.value = awards.value.filter(award => award.awardId !== awardId)
    }

    return {
        awards,
        setAwards,
        addAward,
        updateAward,
        deleteAward
    }
})